CREATE OR REPLACE PACKAGE ORAVC_ENGINE_WEB AS

/*
<main_description>
  creator: Andrey Tsyganov
     date: August, 2011
  contact: atsygan@gmail.com, A.Tsyganov@rug.nl
  (c) 2011, all rights recerved

  Developer of this package is NOT responsible in case of any change of this code by its users
  and also NOT responsible for any bugs in the functionality of the package, however support can be provided

  This package is a basic Web Interface for Version Controll package. (ORAVC_ENGINE)
  Used the following sources for default css of the page:
  http://www.alovefordesign.com/css/create-an-apple-style-menu-purely-in-css3-no-images-required/
  http://pythoughts.com/table-style-css/
</main_description>

*/
G_BASE_URI            CONSTANT VARCHAR2(50) := 'document.body.baseURI';

G_CSS_STATIC          CONSTANT VARCHAR2(50) := 'static';
G_CSS_FIXED           CONSTANT VARCHAR2(50) := 'fixed';
G_CSS_NO_CSS1         CONSTANT VARCHAR2(50) := 'no css';
G_CSS_NO_CSS2         CONSTANT VARCHAR2(50) := 'none';

/*
<comments>
  <function>
    oravc_webInfo
  </function>

  <return>
    CLOB
  </return>

  <description>
    Main function for Version Controll default interface. Calling this function
    user will have as the result HTML page with display of version and there comparation.
    Main parameter - p_base_url. This URL will be used to formulate HTML Form submit.
    example of p_base_url: http://localhost:8080:/oravc/oravc.jsp
    It is fine to call just the following code to have HTML page:
    oravc_webInfo('http://localhost:8080:/oravc/oravc.jsp');

    WORKS FOR Google Chrom, Mozilla Firefox and Apple Safari
    Had not been tested with IE!
  </description>

  <parameters>
    <IN>
      [p_base_url]                    [base url fro HTML page]                                                                                                                        [VARCHAR2]
      [p_tab]                         [html page tab number to display]                                                                                                               [NUMBER]
      [p_tab_prev]                    [html page which called current tab.  ]                                                                                                         [NUMBER]
      [p_object_version]              [version controll obeject version id 1]                                                                                                         [VARCHAR2]
      [p_object_version_child]        [version controll obeject version id 2]                                                                                                         [VARCHAR2]
      [p_filters]                     [filter string separated by ";" with names of objects which versions should be taken into account]                                              [CLOB]
      [p_forceCompare]                [forces comparation of two version not from the same tree]                                                                                      [NUMBER]
      [p_report_type]                 [report type: 1 (all-in-on html), 2 (all-in-one clob), 3-side-by-side html), 4(side-by-side clob)]                                              [NUMBER]
      [p_logs_to_display]             [if mode is to show VC Log, then this parameter tells how many log messages to display (default 50)]                                            [NUMBER]
      [p_custom_css]                  [if NULL then default css used else if there is a need to display this page with custom css parameter should contain {style} tag as well]       [CLOB]        [NULL]
      [p_show_menu_filter]            [Show filter menu option. By default it is shown]                                                                                               [NUMBER]      [0]
      [p_show_menu_oravclog]          [Show logmessages menu option. By default it is shown]                                                                                          [NUMBER]      [0]
      [p_show_menu_objectversion]     [Show particular version information menu option . By default it is shown]                                                                      [NUMBER]      [0]
      [p_show_menu_versioncompare]    [Show versions compare menu option. By default it is shown]                                                                                     [NUMBER]      [0]
      [p_show_menu_versiongenerate]   [Show version generator menu option. By default it is shown]                                                                                    [NUMBER]      [0]
      [p_show_menu_oravcapi]          [Show ORAVC engeine API informstion display menu option. By default it is shown]                                                                [NUMBER]      [0]
    </IN>
  </parameters>

  <version>
    [1.0] [01-10-2011] [Andrey Tsyganov] [creation] []
    [1.1] [01-02-2012] [Andrey Tsyganov] [change]   [display version filters are now availeble]
    [1.2] [01-03-2012] [Andrey Tsyganov] [change]   [clobs comparation is excluded from the interface functionality]
    [1.3] [05-02-2014] [Andrey Tsyganov] [change]   [1) Two styles FIXED and STATIC were added for menu. 
                                                        Default if FIXED - always on top of the page
                                                     2) Submit form now generated dynamically with the javascript.
                                                        Thus the result can be put on the pages with the ither HTML Forms
                                                    ]
  </version>

</comments>
*/
FUNCTION oravc_webInfo(
           p_base_url                   VARCHAR2
          ,p_tab                        NUMBER
          ,p_tab_prev                   NUMBER
          ,p_object_version             VARCHAR2
          ,p_object_version_child       VARCHAR2
          ,p_filters                    CLOB
          ,p_forceCompare               NUMBER
          ,p_report_type                NUMBER
          ,p_logs_to_display            NUMBER
          ,p_custom_css                 CLOB      := G_CSS_FIXED
          ,p_show_title                 NUMBER    := 0
          ,p_show_menu_admininfo        NUMBER    := 0
          ,p_show_menu_filter           NUMBER    := 0
          ,p_show_menu_oravclog         NUMBER    := 0
          ,p_show_menu_objectversion    NUMBER    := 0
          ,p_show_menu_versioncompare   NUMBER    := 0
          ,p_show_menu_versiongenerate  NUMBER    := 0
          ,p_show_menu_oravcapi         NUMBER    := 0
          ) RETURN CLOB;

/*
<comments>
  <procedure>
    viewer
  </procedure>

  <description>
    This procedure will print the result of the oravc_webInfo using htp package
    Main parameter - p_base_url. 
    Using this function one can configure the OraVC Viewer directlly from DAD
    
    p_base_url parameter can be: 
    This URL will be used to formulate HTML Form submit.
    example of p_base_url: http://localhost:8080:/oravc/oravc.jsp
    It is fine to call just the following code to have HTML page:
    oravc_webInfo('http://localhost:8080:/oravc/oravc.jsp');

    WORKS FOR Google Chrom, Mozilla Firefox and Apple Safari
    Had not been tested with IE!

    To add logout link one can user the following code example:
      htp.p('<script>');
      IF p_base_url = G_BASE_URI THEN
        htp.p('var g_base_url = ' || ORAVC_ENGINE_WEB.G_BASE_URI ||';');
      ELSE
        htp.p('var g_base_url = ''' || + p_base_url || ''';');
      END IF;
      htp.p('</script>');
      htp.p('<div id="oravc_menu50"><a href="#" onclick=''window.location=g_base_url+"_logout"''>Logout</a></div>'); 

   The style: id=oravc_menu50, will put Logout link at the top left of the screen.

  </description>

  <parameters>
    <IN>
      [p_base_url]                    [base url fro HTML page]                                                                                                                        [VARCHAR2]    [document.body.baseURI]
      [p_tab]                         [html page tab number to display]                                                                                                               [NUMBER]      [NULL]
      [p_tab_prev]                    [html page which called current tab.  ]                                                                                                         [NUMBER]      [NULL]
      [p_object_version]              [version controll obeject version id 1]                                                                                                         [VARCHAR2]    [NULL]
      [p_object_version_child]        [version controll obeject version id 2]                                                                                                         [VARCHAR2]    [NULL]
      [p_filters]                     [filter string separated by ";" with names of objects which versions should be taken into account]                                              [CLOB]        [NULL]
      [p_forceCompare]                [forces comparation of two version not from the same tree]                                                                                      [NUMBER]      [NULL]
      [p_report_type]                 [report type: 1 (all-in-on html), 2 (all-in-one clob), 3-side-by-side html), 4(side-by-side clob)]                                              [NUMBER]      [NULL]
      [p_logs_to_display]             [if mode is to show VC Log, then this parameter tells how many log messages to display (default 50)]                                            [NUMBER]      [NULL]
      [p_custom_css]                  [if NULL then default css used else if there is a need to display this page with custom css parameter should contain {style} tag as well]       [CLOB]        [NULL]
      [p_show_menu_filter]            [Show filter menu option. By default it is shown]                                                                                               [NUMBER]      [0]
      [p_show_menu_oravclog]          [Show logmessages menu option. By default it is shown]                                                                                          [NUMBER]      [0]
      [p_show_menu_objectversion]     [Show particular version information menu option . By default it is shown]                                                                      [NUMBER]      [0]
      [p_show_menu_versioncompare]    [Show versions compare menu option. By default it is shown]                                                                                     [NUMBER]      [0]
      [p_show_menu_versiongenerate]   [Show version generator menu option. By default it is shown]                                                                                    [NUMBER]      [0]
      [p_show_menu_oravcapi]          [Show ORAVC engeine API informstion display menu option. By default it is shown]                                                                [NUMBER]      [0]
    </IN>
  </parameters>

  <version>
    [1.0] [05-10-2014] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
PROCEDURE viewer(
           p_base_url                   VARCHAR2  := G_BASE_URI
          ,p_tab                        NUMBER    := NULL
          ,p_tab_prev                   NUMBER    := NULL
          ,p_object_version             VARCHAR2  := NULL
          ,p_object_version_child       VARCHAR2  := NULL
          ,p_filters                    CLOB      := NULL
          ,p_forceCompare               NUMBER    := NULL
          ,p_report_type                NUMBER    := NULL
          ,p_logs_to_display            NUMBER    := NULL
          ,p_custom_css                 CLOB      := G_CSS_FIXED
          ,p_show_title                 NUMBER    := 0
          ,p_show_menu_admininfo        NUMBER    := 0
          ,p_show_menu_filter           NUMBER    := 0
          ,p_show_menu_oravclog         NUMBER    := 0
          ,p_show_menu_objectversion    NUMBER    := 0
          ,p_show_menu_versioncompare   NUMBER    := 0
          ,p_show_menu_versiongenerate  NUMBER    := 0
          ,p_show_menu_oravcapi         NUMBER    := 0
          );


/*
<comments>
  <function>
    oravc_getDefaultCSS
  </function>

  <return>
    CLOB
  </return>

  <description>
    Return default CSS for the ORAVC Web display
  </description>

  <version>
    [1.0] [01-03-2012] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION oravc_getDefaultCSS RETURN CLOB;


/*
FUNCTION showVersionCompare(
           p_object_version             VARCHAR2 := NULL
          ,p_object_version_child       VARCHAR2 := NULL
          ,p_forceCompare               NUMBER   := 0
          ,p_report_type                NUMBER   := 0
          ,p_filters                    CLOB     := NULL
         ) RETURN CLOB;
*/

END ORAVC_ENGINE_WEB;
/


CREATE OR REPLACE PACKAGE BODY ORAVC_ENGINE_WEB AS

C_PACKAGE_NAME                                   CONSTANT VARCHAR2(255) := 'ORAVC_ENGINE_WEB';
C_FILTERID_CONNECTOR                             CONSTANT VARCHAR2(2)   := '=>';
C_FILTERVERSIONSCOUNT                            CONSTANT VARCHAR2(20)  := 'FILTERVERSIONSCOUNT';
C_DEF_FILTERVERSIONSCOUNT                        CONSTANT VARCHAR2(20)  := '10';
C_TOCHAR_DATEFORMAT                              CONSTANT VARCHAR2(255) := 'dd-mm-yyyy hh24:mi:ss';

-- main default css
C_CSS_MENU_TAG                              CONSTANT VARCHAR2(255) := '<###CSS_MENU_TAG###>';
G_WEBFORM_DEFAULT_CSS               CLOB :=
'
body {
  background: white;
}

tr.oravc_tr' || ORAVC_ENGINE.get_C_DELETED || chr(10) ||
'{
  background: #ffabab;
}


tr.oravc_tr' || ORAVC_ENGINE.get_C_ADDED || chr(10) ||
'{
  background: #fcf3c0;
}

tr.oravc_tr' || ORAVC_ENGINE.get_C_UNCHANGED || chr(10) ||
'{
  background: white;
}

tr.oravc_tr' || ORAVC_ENGINE.get_C_MUTATED || chr(10) ||
'{
  background: #d8fcc0;
}

tr.oravc_tr' || ORAVC_ENGINE.get_C_ADDED_CHAR2 || chr(10) ||
'{
  background: #c0fcfa;
}

td.oravc_lighttd:hover {
  background-color: #aaa;
}

.oravc_select {
}

.oravc_button {
  vertical-align: center;
}

.oravc_checkbox {
cursor:pointer;
}

#oravc_submittable {
  width: 100%
  border: 1px solid #B0B0B0;
}

#oravc_submittable th {
  font-weight: bold;
  text-align: right;
}

#oravc_submittable td {
  white-space: nowrap;
  text-align: left;
}

#oravc_log_displaytable {
  width: 100%
  border: 1px solid #B0B0B0;
}

#oravc_log_displaytable th {
  background: -moz-linear-gradient(top, #F0F0F0 0, #DBDBDB 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #F0F0F0), color-stop(100%, #DBDBDB));
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=''#F0F0F0'', endColorstr=''#DBDBDB'', GradientType=0);
  border: 1px solid #B0B0B0;
  color: #444;
  font-size: 16px;
  font-weight: bold;
}

#oravc_log_displaytable td {
  white-space: nowrap;
  text-align: left;
}

#oravc_log_displaytable tr:hover, tr.highlight {
  background-color: #aaa;
}

#oravc_api_displaytable {
  border-spacing: 0px;
}

#oravc_api_displaytable td {
  white-space: nowrap;
  text-align: left;
}

#oravc_api_displaytable tr {
  background: white;
}

#oravc_api_displaytable th {
  background: -moz-linear-gradient(top, #F0F0F0 0, #DBDBDB 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #F0F0F0), color-stop(100%, #DBDBDB));
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=''#F0F0F0'', endColorstr=''#DBDBDB'', GradientType=0);
  border: 1px solid #B0B0B0;
  color: #444;
  font-size: 16px;
  font-weight: bold;
  text-align: left;
  vertical-align: top;
}

#oravc_source_displaytable {
  border-spacing: 0px;
}

#oravc_source_displaytable td {
  white-space: nowrap;
  text-align: left;
}

#oravc_source_displaytable tr {
  background: white;
}

#oravc_filter_displaytable1 {
  border-spacing: 0px;
}

#oravc_filter_displaytable2 {
  border-spacing: 0px;
  margin-left: auto;
  margin-right: auto;
}

#oravc_filter_displaytable2 th {
  vertical-align: top;
  background: -moz-linear-gradient(top, #F0F0F0 0, #DBDBDB 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #F0F0F0), color-stop(100%, #DBDBDB));
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=''#F0F0F0'', endColorstr=''#DBDBDB'', GradientType=0);
  border: 1px solid #B0B0B0;
  color: #444;
  font-size: 16px;
  font-weight: bold;
  text-align: left;
}

#oravc_filter_displaytable2 td {
  white-space: nowrap;
  text-align: left;
  vertical-align: top;
}

#oravc_filter_displaytable2 tr {
  background: white;
}

#oravc_reportable1 {
  border: 0px solid #B0B0B0;
  border-spacing: 0px;
}

#oravc_reportable1 th {
  background: -moz-linear-gradient(top, #F0F0F0 0, #DBDBDB 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #F0F0F0), color-stop(100%, #DBDBDB));
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=''#F0F0F0'', endColorstr=''#DBDBDB'', GradientType=0);
  border: 1px solid #B0B0B0;
  color: #444;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
}

#oravc_reportable1 td {
  white-space: nowrap;
  text-align: left;
  font-weight: bold;
}

#oravc_reportable1 tr {
  background: white;
}

#oravc_reportable2 {
  width: 100%
  border: 1px solid #B0B0B0;
}

#oravc_reportable2 th {
  background: -moz-linear-gradient(top, #F0F0F0 0, #DBDBDB 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #F0F0F0), color-stop(100%, #DBDBDB));
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=''#F0F0F0'', endColorstr=''#DBDBDB'', GradientType=0);
  border: 1px solid #B0B0B0;
  color: #444;
  font-size: 16px;
  font-weight: bold;
}

#oravc_reportable2 td {
  white-space: nowrap;
  text-align: left;
}

#oravc_reportable2 tr:hover, tr.highlight {
  background-color: #aaa;
}

#oravc_main_menu_div1 {
  width: 100%;
  margin-left: auto;
  margin-right: auto;

}


#oravc_menu0     {
width: 90%;
position: fixed;
background-color:#fff5dd;
border-bottom: 3px solid black;
top: 0px;
right: 0;
height: 30px;
z-index: 500;
}


#oravc_menu0     {
width: 100%;
position: ' || C_CSS_MENU_TAG || ';
background-color:#fff5dd;
border-bottom: 3px solid black;
top: 0px;
right: 0;
height: 30px;
z-index: 500;
}

#oravc_menu-50     {
width: 100%;
background-color:white;
z-index: 400;
height: 30px;
}

#oravc_menu50     {
width: 10%;
position: ' || C_CSS_MENU_TAG || ';
background-color:#fff5dd;
top: 0;
top: 0;
left: 0;
align: right;
z-index: 600;
height: 30px;
vertical-align: middle;
border-bottom: 3px solid black;
}


#oravc_menu     {
  float: right;
  padding: 0;
  margin: 0;

  position: ' || C_CSS_MENU_TAG || ';;
  top: 0;
  right: 0;
}

#oravc_header div {
}

#oravc_menu ul  {
  border-top: #f3f3f3 1px solid;
  padding: 0;
  margin: 0;
  float: left;
}

#oravc_menu li  {
  float: left;
  list-style: none;
  background: none;
  margin-right: 1px;
}

#oravc_menu li.textli {
  background: #fff5dd;
  font-size: 22px;
  font-weight: bold;
  margin-right: 9pt
}


#oravc_menu a { outline: none; }

#oravc_menu li a:link, #oravc_menu li a:visited {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: bold;
  display: block;
  color: #262626;
  padding: 5px 16px;
  text-decoration: none;
  text-transform: capitalize;

  /* CSS3 Text Shadow */
  text-shadow: 0px 1px 1px #fff;

  /* CSS3 Background Gradient */
  background-image: -moz-linear-gradient(top, #cacaca, #848484);
  background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#cacaca), to(#848484));
}
#oravc_menu li a:hover    {
  cursor: pointer;
  color: #fff;
  text-shadow: 0px -1px 1px #000;

  /* Background Gradient */
  background-image: -moz-linear-gradient(top, #929292, #545454);
  background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#929292), to(#545454));
}
#oravc_menu li:first-child a, #oravc_menu ul {
  /* Rounded Corners */
  -moz-border-radius-topleft: 5px;
  -moz-border-radius-bottomleft: 5px;
  -webkit-border-top-left-radius: 5px;
  -webkit-border-bottom-left-radius: 5px;
}

a.active:link, a.active:active, a.active:visited  {
  color: #fff !important;
  text-shadow: 0px -1px 1px #000!important;
  background-image: -moz-linear-gradient(top, #444, #666)!important;
  background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#444), to(#666))!important;

  /* Box Shadow */
  box-shadow: inset 0 0 5px #000;
  -moz-box-shadow: inset 0 0 5px #000;
  -webkit-box-shadow: inset 0 0 5px #000;
}

.oravc_please_wait {
  left: 0;
  position: fixed;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 900;
  background-color: black;
  color:red;
  opacity:0.4;
  filter:alpha(opacity=40);
  text-align:center;
  display:none;
}

';

-- main javascript
G_WEBFORM_JAVASCRIPT                  CLOB :=
'
  function checkboxAll(p_tochangeCheckBoxName, p_status) {
    var checkboxes = document.getElementsByName(p_tochangeCheckBoxName);
    for (var i = 0; i < checkboxes.length; i++)
      checkboxes[i].checked = p_status;

    if (p_status == false)
      document.getElementById("' || C_FILTERVERSIONSCOUNT || '").value = -1;
  }

  function checkboxReverse(p_tochangeCheckBoxName) {
    var checkboxes = document.getElementsByName(p_tochangeCheckBoxName);
    for (var i = 0; i < checkboxes.length; i++)
      checkboxes[i].checked = !checkboxes[i].checked;
  }

  function onSourceLineMouseAction(tdobj, chbxid) {
    var checkbox = document.getElementById(chbxid);
    checkbox.checked = !checkbox.checked;
  }


  function showDiv(object_name){
    var obj = document.getElementById(object_name);

    obj.style.visibility = ''visible'';
    obj.style.display = ''block'';
  }

  function hideDiv(object_name){
    var obj = document.getElementById(object_name);

    obj.style.visibility = ''hidden'';
    obj.style.display = ''none'';
  }


  function oraVCsubmitformGeneral(pTabNumber){
    document.oraVCsubmitForm.p_tab.value                  = pTabNumber;
    document.oraVCsubmitForm.p_object_version.value       = "";
    document.oraVCsubmitForm.p_object_version_child.value = "";
    document.oraVCsubmitForm.p_forceCompare.value         = "";
    document.oraVCsubmitForm.p_report_type.value          = "";
    document.oraVCsubmitForm.p_logs_to_display.value      = "";
    //document.oraVCsubmitForm.p_filters.value              = "";

    document.getElementById("waiting-overlay").style.display="block";

    document.oraVCsubmitForm.submit();
  }

  function oraVCsubmitformForTab1(pprefix){
    var dd2_0 = document.getElementById(pprefix+"dd2_0");

    document.oraVCsubmitForm.p_tab.value                  = 1;
    document.oraVCsubmitForm.p_object_version.value       = "";
    document.oraVCsubmitForm.p_object_version_child.value = dd2_0[dd2_0.selectedIndex].value;
    document.oraVCsubmitForm.p_forceCompare.value         = 0
    document.oraVCsubmitForm.p_report_type.value          = ""
    document.oraVCsubmitForm.p_logs_to_display.value      = ""

    document.getElementById("waiting-overlay").style.display="block";
    document.oraVCsubmitForm.submit();
  }

  function oraVCsubmitformForTab2(pprefix){
    var dd1_0 = document.getElementById(pprefix+"dd1_0");
    var dd2_0 = document.getElementById(pprefix+"dd2_0");

    document.oraVCsubmitForm.p_tab.value                  = 2;
    document.oraVCsubmitForm.p_object_version.value       = dd1_0[dd1_0.selectedIndex].value;
    document.oraVCsubmitForm.p_object_version_child.value = dd2_0[dd2_0.selectedIndex].value;

    var iPara = 0;
    var l_checkbox = document.getElementById(pprefix+"forceCompare");
    if (l_checkbox.checked == true)
      iPara = 1;

    document.oraVCsubmitForm.p_forceCompare.value         = iPara
    document.oraVCsubmitForm.p_report_type.value          = document.getElementById(pprefix+"reportType").value
    document.oraVCsubmitForm.p_logs_to_display.value      = ""

    document.getElementById("waiting-overlay").style.display="block";
    document.oraVCsubmitForm.submit();
  }

  function oraVCsubmitformForTab4(pprefix){
    var dd1_0 = document.getElementById(pprefix+"dd1_0");
    var dd2_0 = document.getElementById(pprefix+"dd2_0");

    document.oraVCsubmitForm.p_tab.value                  = 4;
    document.oraVCsubmitForm.p_object_version.value       = dd1_0[dd1_0.selectedIndex].value;
    document.oraVCsubmitForm.p_object_version_child.value = dd2_0[dd2_0.selectedIndex].value;

    var iPara = 0;
    var l_checkbox = document.getElementById(pprefix+"forceCompare");
    if (l_checkbox.checked == true)
      iPara = 1;

    document.oraVCsubmitForm.p_forceCompare.value         = iPara
    document.oraVCsubmitForm.p_report_type.value          = 1
    document.oraVCsubmitForm.p_logs_to_display.value      = ""

    document.getElementById("waiting-overlay").style.display="block";
    document.oraVCsubmitForm.submit();
  }

  function oraVCsubmitformForTab5(pprefix){
    document.oraVCsubmitForm.p_tab.value                  = 5;
    document.oraVCsubmitForm.p_object_version.value       = "";
    document.oraVCsubmitForm.p_object_version_child.value = "";
    document.oraVCsubmitForm.p_forceCompare.value         = 0
    document.oraVCsubmitForm.p_report_type.value          = ""
    document.oraVCsubmitForm.p_logs_to_display.value      = document.getElementById(pprefix+"logsmToDisplay").value

    document.getElementById("waiting-overlay").style.display="block";
    document.oraVCsubmitForm.submit();
  }

  function oraVCsubmitformForTab6(pTabNumber){
    document.oraVCsubmitForm.p_tab.value                  = pTabNumber;
    document.oraVCsubmitForm.p_object_version.value       = "";
    document.oraVCsubmitForm.p_object_version_child.value = "";
    document.oraVCsubmitForm.p_forceCompare.value         = "";
    document.oraVCsubmitForm.p_report_type.value          = "";
    document.oraVCsubmitForm.p_logs_to_display.value      = "";

    var checkboxes = document.getElementsByName("filterCheckBox");
    var filterLines = document.getElementsByName("filterLine");
    var filter_values = "";

    for (var i=0; i < checkboxes.length; i++) {
      if (checkboxes[i].checked)
        filter_values += filterLines[i].id + ";";
    }
    var daysElem = document.getElementsByName("' || C_FILTERVERSIONSCOUNT ||  '");
    filter_values += daysElem[0].name + "' || C_FILTERID_CONNECTOR || '" + daysElem[0].value + ";";


    document.oraVCsubmitForm.p_filters.value      = filter_values;

    document.getElementById("waiting-overlay").style.display="block";
    document.oraVCsubmitForm.submit();
  }
';

/*
<comments>
  in package specification

</comments>
*/
FUNCTION oravc_getDefaultCSS RETURN CLOB IS
BEGIN
  RETURN G_WEBFORM_DEFAULT_CSS;
END oravc_getDefaultCSS;



/*
<comments>
  in package specification

</comments>
*/
FUNCTION addAdminOptionsTable RETURN CLOB IS

  l_result            CLOB := null;
BEGIN
  dbms_lob.createtemporary(l_result, TRUE);

  dbms_lob.append(l_result, '<table id="oravc_api_displaytable">' || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th></th>'                           || chr(10));
  dbms_lob.append(l_result, '<th>Admin commands</th>'             || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Create user schema AFTER DDL trigger for the OraVC engine</th>'   || chr(10));
  dbms_lob.append(l_result, '<td> ' ||
                                        ' 1) Login as OraVC user schema owner<br>'
                                      ||' 2) Add user to monitor<br>'
                                      || ORAVC_ENGINE.getClobForHTML(' execute oravc_engine.oravc_add_user2monitor(<username>);')
                                      ||'<br>Create trigger in the user schema:<br>'
                                      ||' 3) Change session schema using the following command:<br>'
                                      || ORAVC_ENGINE.getClobForHTML(' alter session set current_schema=<username>;')
                                      ||' 4) Execute trigger generation command as follows:<br>'
                                      || ORAVC_ENGINE.getClobForHTML(' begin execute immediate oravc.oravc_trigger.oravc_getVCTriggerTextForUser(<username>); end;')
                                      ||'<br>'
                                      || chr(10)
                                      );
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<th>Add user to monitor</th>'        || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_add_user2monitor(<username>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Delere user to monitor</th>'     || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_delete_user2monitor(<username>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Add sys event to monitor</th>'                         || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_add_event2monitor(<event name>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Delete sys event to monitor</th>'                      || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_delete_event2monitor(<event name>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Add object type to monitor</th>'                       || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_add_objtype2monitor(<event name>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Delete object type to monitor</th>'                    || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_delete_objtype2monitor(<event name>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Start OraVC scheduler job</th>'                        || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_job.oravc_start_plvc_job(<job interval(minutes)>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Start OraVC scheduler job with retention policy</th>'  || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_job.oravc_start_plvc_job(<job interval(minutes)>, <version retention days>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Delete OraVC scheduler job</th>'                       || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_job.oravc_drop_plvc_job;') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Synchronize all versions manually</th>'                || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_main_vc;') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Synchronize all versions and clean old </th>'          || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_main_vc(null, null, null, <retention days>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Synchronize some versions</th>'                        || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_main_vc(<owner>, <object name>, <object type>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Synchronize some versions and clean old </th>'         || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_main_vc(<owner>, <object name>, <object type>, <retention days>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Add OraVC schema trigger for registered user </th>'    || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_compileVCTriggerForUser(<username>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Drop OraVC schema trigger for registered user </th>'   || chr(10));
  dbms_lob.append(l_result, '<td>' || ORAVC_ENGINE.getClobForHTML('execute oravc_engine.oravc_dropVCTriggerForUser(<username>);') ||  '</td>'                       || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  dbms_lob.append(l_result, '</table>'                                                  || chr(10));

  RETURN l_result;
END addAdminOptionsTable;

/*
<comments>
  <function>
    formatClobToJavascriptString
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function retunes CLOB that can be put into Javascript string betwen "..."
  </description>

  <parameters>
    <IN>
      [p_clob]                  [clob to replace values]   [CLOB]
    </IN>
  </parameters>

  <version>
    [1.0] [01-10-2011] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION formatClobToJavascriptString (
          p_clob                    CLOB
         ) RETURN CLOB IS
  l_result                          CLOB;
BEGIN
  l_result := REPLACE(p_clob, '\', '\\');
  l_result := REPLACE(l_result, '"', '\"');
  l_result := REPLACE(l_result, '''', '\''');
  l_result := REPLACE(l_result, chr(13), '\r');
  l_result := REPLACE(l_result, chr(10), '\n');
  l_result := REPLACE(l_result, chr(8), '\b');
  l_result := REPLACE(l_result, chr(9), '\t');

  RETURN l_result;
END formatClobToJavascriptString;

/*
<comments>
  <function>
    showVersionsFilter
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function retunes CLOB html to display version filter div, to filter content of drop downs
  </description>

  <parameters>
    <IN>
      [p_prefix]                  [tab prefix for id's of html components for different tabs]   [VARCHAR2]
      [p_tabnumber]               [tab where to go after filter save]                           [NUMBER]
    </IN>
  </parameters>

  <version>
    [1.0] [01-10-2011] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showVersionsFilter (
           p_prefix                     VARCHAR2
          ,p_tabnumber                  NUMBER
         ) RETURN CLOB IS

  l_result                              CLOB           := NULL;
  l_id                                  VARCHAR2(4000) := NULL;
  l_td_class                            VARCHAR2(255)  := ' class="oravc_lighttd" ';

  CURSOR object_owners_cur IS
    SELECT obj_owner
          ,count(*) as rows_count
      FROM (SELECT DISTINCT
                   vco_obj_owner as obj_owner
                  ,vco_obj_type  as obj_type
                  ,vco_obj_name  as obj_name
              FROM oravc_obj
           )
     GROUP BY obj_owner
     ORDER BY 1;

  CURSOR object_types_cur IS
    SELECT obj_owner
          ,obj_type
          ,count(*) as rows_count
      FROM (SELECT DISTINCT
                   vco_obj_owner as obj_owner
                  ,vco_obj_type  as obj_type
                  ,vco_obj_name  as obj_name
              FROM oravc_obj
           )
     GROUP BY obj_owner, obj_type
     ORDER BY 1, 2;

  CURSOR object_names_cur IS
    SELECT vco_obj_owner as obj_owner
          ,vco_obj_type  as obj_type
          ,vco_obj_name  as obj_name
      FROM oravc_obj
     ORDER BY 1, 2, 3;

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  dbms_lob.append(l_result, '<table id="oravc_filter_displaytable1">'                      || chr(10));
  dbms_lob.append(l_result, '<tr>'          || chr(10));
  dbms_lob.append(l_result, '<td>'       || chr(10));

  dbms_lob.append(l_result, '<table id="oravc_reportable1">'                      || chr(10));
  dbms_lob.append(l_result, '<tr>'                      || chr(10));
  dbms_lob.append(l_result, '<td>'                      || chr(10));
  dbms_lob.append(l_result, 'Filter objects to operate:'                      || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '<td>'                      || chr(10));
  dbms_lob.append(l_result, '<INPUT class="oravc_button" type="button"   id="excludeAllButton" value="No filtering" onClick="checkboxAll(''filterCheckBox'', false);"/>'         || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '<td>'                      || chr(10));
  dbms_lob.append(l_result, '<INPUT class="oravc_button" type="button"   id="includeAllButton" value="Include All" onClick="checkboxAll(''filterCheckBox'', true);"/>'         || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '<td>'                      || chr(10));
  dbms_lob.append(l_result, '<INPUT class="oravc_button" type="button"   id="reverseButton" value="Reverse exclude/include" onClick="checkboxReverse(''filterCheckBox'');"/>'         || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '<td>'                      || chr(10));
  dbms_lob.append(l_result, '<INPUT class="oravc_button" type="button" name="filterButton" value="Apply filter" onClick="oraVCsubmitformForTab6(''' || p_tabnumber || ''')"/>'         || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '</tr>'                      || chr(10));
  dbms_lob.append(l_result, '<tr>'                      || chr(10));
  dbms_lob.append(l_result, '<td colspan=10>'                      || chr(10));
  dbms_lob.append(l_result, '*If nothing selected, then no filter applyed'                      || chr(10));
  dbms_lob.append(l_result, '</tr>'                      || chr(10));
  dbms_lob.append(l_result, '<tr>'                      || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '<td colspan=10>'                      || chr(10));
  dbms_lob.append(l_result, '*If number of versions <= 0  will mean  "show ALL vesrions"'                      || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '</tr>'                      || chr(10));
  dbms_lob.append(l_result, '</table><br><br>'                      || chr(10));


  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '</tr>'                      || chr(10));
  dbms_lob.append(l_result, '<tr>'          || chr(10));
  dbms_lob.append(l_result, '<td>'       || chr(10));

  dbms_lob.append(l_result, '<table id="oravc_filter_displaytable2">'                      || chr(10));

  dbms_lob.append(l_result, '<tr>'                      || chr(10));
  dbms_lob.append(l_result, '<th>Display last (n) versions:</th>'                      || chr(10));
  dbms_lob.append(l_result, '<td>'                      || chr(10));
  dbms_lob.append(l_result, '<input class="oravc_numberbox" type="number" name="' || C_FILTERVERSIONSCOUNT || '" id="' || C_FILTERVERSIONSCOUNT || '" value=' || C_DEF_FILTERVERSIONSCOUNT || '>'                  || chr(10));
  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '</tr>'                      || chr(10));

  dbms_lob.append(l_result, '<tr>'                      || chr(10));
  dbms_lob.append(l_result, '<th>Filter on:</th>'  || chr(10));
  dbms_lob.append(l_result, '<th>Owner</th>'  || chr(10));
  dbms_lob.append(l_result, '<th>[OR]</th>'  || chr(10));
  dbms_lob.append(l_result, '<th>Object type</th>'  || chr(10));
  dbms_lob.append(l_result, '<th>[OR]</th>'  || chr(10));
  dbms_lob.append(l_result, '<th>Object name</th>'  || chr(10));


  dbms_lob.append(l_result, '<tr>'          || chr(10));
  dbms_lob.append(l_result, '<td></td>'  || chr(10));
  dbms_lob.append(l_result, '<td>'       || chr(10));
  dbms_lob.append(l_result, '<table>'                      || chr(10));
  FOR object_owners_rec IN object_owners_cur LOOP
    l_id :=  C_FILTERID_CONNECTOR || object_owners_rec.obj_owner;
    dbms_lob.append(l_result, '<tr>'       || chr(10));
    dbms_lob.append(l_result, '<td>'       || chr(10));
    dbms_lob.append(l_result, '<input class="oravc_checkbox" name="filterCheckBox" id="filterCheckBox' || l_id ||'" type="checkbox"></input>'  || chr(10)       || chr(10));
    dbms_lob.append(l_result, '</td>'       || chr(10));
    dbms_lob.append(l_result, '<td>'       || chr(10));
    dbms_lob.append(l_result, '<td' || l_td_class || 'id="' || l_id || '" name="filterLine" onmousedown="onSourceLineMouseAction(this, ''filterCheckBox' || l_id || ''')">');
    dbms_lob.append(l_result, object_owners_rec.obj_owner       || chr(10));
    dbms_lob.append(l_result, '</td>'       || chr(10));
    dbms_lob.append(l_result, '</tr>'         || chr(10));

    FOR i IN 1..object_owners_rec.rows_count - 1 LOOP
      dbms_lob.append(l_result, '<tr><td><br></td></tr>'          || chr(10));
    END LOOP;

  END LOOP;
  dbms_lob.append(l_result, '</table>'                      || chr(10));
  dbms_lob.append(l_result, '</td>'       || chr(10));
  dbms_lob.append(l_result, '<td></td>'  || chr(10));

  dbms_lob.append(l_result, '<td>'       || chr(10));
  dbms_lob.append(l_result, '<table>'                      || chr(10));
  FOR object_types_rec IN object_types_cur LOOP
    l_id := C_FILTERID_CONNECTOR || object_types_rec.obj_owner || C_FILTERID_CONNECTOR || object_types_rec.obj_type;
    dbms_lob.append(l_result, '<tr>'          || chr(10));
    dbms_lob.append(l_result, '<td>'       || chr(10));
    dbms_lob.append(l_result, '<input class="oravc_checkbox" name="filterCheckBox" id="filterCheckBox' || l_id || '" type="checkbox"></input>'  || chr(10)       || chr(10));
    dbms_lob.append(l_result, '</td>'       || chr(10));
    dbms_lob.append(l_result, '<td>'       || chr(10));
    dbms_lob.append(l_result, '<td' || l_td_class || ' id="' || l_id || '" name="filterLine" onmousedown="onSourceLineMouseAction(this, ''filterCheckBox' || l_id || ''')">');
    dbms_lob.append(l_result, object_types_rec.obj_type       || chr(10));
    dbms_lob.append(l_result, '</td>'       || chr(10));
    dbms_lob.append(l_result, '</tr>'         || chr(10));

    FOR i IN 1..object_types_rec.rows_count - 1 LOOP
      dbms_lob.append(l_result, '<tr><td><br></td></tr>'          || chr(10));
    END LOOP;
  END LOOP;
  dbms_lob.append(l_result, '</table>'                      || chr(10));
  dbms_lob.append(l_result, '</td>'       || chr(10));
  dbms_lob.append(l_result, '<td></td>'  || chr(10));


  dbms_lob.append(l_result, '<td>'       || chr(10));
  dbms_lob.append(l_result, '<table>'                      || chr(10));
  FOR object_names_rec IN object_names_cur LOOP
    l_id := C_FILTERID_CONNECTOR || object_names_rec.obj_owner ||C_FILTERID_CONNECTOR || object_names_rec.obj_type  || C_FILTERID_CONNECTOR || object_names_rec.obj_name;
    dbms_lob.append(l_result, '<tr>'          || chr(10));
    dbms_lob.append(l_result, '<td>'       || chr(10));
    dbms_lob.append(l_result, '<input class="oravc_checkbox" name="filterCheckBox" id="filterCheckBox' || l_id || '" type="checkbox"></input>'  || chr(10)       || chr(10));
    dbms_lob.append(l_result, '</td>'       || chr(10));
    dbms_lob.append(l_result, '<td>'       || chr(10));
    dbms_lob.append(l_result, '<td' || l_td_class || ' id="'  || l_id || '" name="filterLine" onmousedown="onSourceLineMouseAction(this, ''filterCheckBox' || l_id || ''')">');

    dbms_lob.append(l_result, object_names_rec.obj_name       || chr(10));
    dbms_lob.append(l_result, '</td>'       || chr(10));
    dbms_lob.append(l_result, '</tr>'         || chr(10));
  END LOOP;
  dbms_lob.append(l_result, '</table>'                      || chr(10));
  dbms_lob.append(l_result, '</td>'       || chr(10));

  dbms_lob.append(l_result, '</tr>'         || chr(10));
  dbms_lob.append(l_result, '</table>'                      || chr(10));

  dbms_lob.append(l_result, '</td>'                      || chr(10));
  dbms_lob.append(l_result, '</tr>'                      || chr(10));
  dbms_lob.append(l_result, '</table>'                      || chr(10));


  RETURN l_result;
END showVersionsFilter;

/*
<comments>
  <function>
    showVersionCompare
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function retunes CLOB html to display report bar fro different tabs
  </description>

  <parameters>
    <IN>
      [p_prefix]                  [tab prefix for id's of html components for different tabs]   [VARCHAR2]
      [p_filters]                 [filters that should be applyed]                              [CLOB]
    </IN>
  </parameters>

  <version>
    [1.0] [01-10-2011] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showVersionsBar (
           p_prefix                     VARCHAR2
          ,p_filters                    CLOB
         ) RETURN CLOB IS

  l_result                              CLOB         := NULL;
  l_filterdays                          NUMBER       := NULL;
  l_filterobj                           CLOB         := NULL;

  CURSOR object_versions_cur(p_filtervesrionscount NUMBER, p_filterobj CLOB) IS
  SELECT * FROM (
    SELECT ovm_obj_version_id                         AS version_id
            ,vco_obj_owner || ' => '
          || vco_obj_type || ' => '
          || vco_obj_name || ' => '
          || to_char(OVM_OBJ_VERSION_DATE, ORAVC_ENGINE.get_C_TOCHAR_DATEFORMAT) || ' => '
          || ovm_obj_version_id             AS version_Value
          ,ROW_NUMBER() OVER (PARTITION BY vco_obj_owner, vco_obj_type, vco_obj_name  ORDER BY OVM_OBJ_VERSION_DATE desc) AS version_number
      FROM oravc_obj_version
          ,oravc_obj
     WHERE vco_obj_vc_id = ovm_obj_vc_id
       AND (   length(p_filterobj) = 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || ';') > 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || C_FILTERID_CONNECTOR || vco_obj_type || ';')  > 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || C_FILTERID_CONNECTOR || vco_obj_type || C_FILTERID_CONNECTOR || vco_obj_name || ';')  > 0
       )
    ORDER BY vco_obj_owner, vco_obj_type, vco_obj_name, ovm_obj_version_id asc
  ) WHERE (p_filtervesrionscount < 1 OR version_number <= p_filtervesrionscount)
  ;
/*
  SELECT * FROM (
     SELECT  ovm_obj_parent                         AS version_id
            ,vco_obj_owner || ' => '
          || vco_obj_type || ' => '
          || vco_obj_name || ' => '
          || to_char(OVM_OBJ_VERSION_DATE, ORAVC_ENGINE.get_C_TOCHAR_DATEFORMAT) || ' => '
          || ovm_obj_parent               As version_Value
          ,ROW_NUMBER() OVER (PARTITION BY vco_obj_owner, vco_obj_type, vco_obj_name  ORDER BY OVM_OBJ_VERSION_DATE desc) AS version_number
      FROM oravc_obj_version  version_main
          ,oravc_obj
     WHERE vco_obj_vc_id = version_main.ovm_obj_vc_id
       AND version_main.ovm_obj_parent IS NOT NULL
       AND (   length(p_filterobj) = 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || ';') > 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || C_FILTERID_CONNECTOR || vco_obj_type || ';')  > 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || C_FILTERID_CONNECTOR || vco_obj_type || C_FILTERID_CONNECTOR || vco_obj_name || ';')  > 0
       )
       AND EXISTS (SELECT vview.ovm_obj_version_id
                     FROM oravc_obj_version vview
                    WHERE vview.ovm_obj_version_id = version_main.ovm_obj_parent
                 )

    ORDER BY vco_obj_owner, vco_obj_type, vco_obj_name, ovm_obj_version_id asc
  ) WHERE (p_filtervesrionscount < 1 OR version_number <= p_filtervesrionscount)
  ;
*/

  CURSOR object_version_childs_cur(p_filtervesrionscount NUMBER, p_filterobj CLOB) IS
  SELECT * FROM (
    SELECT ovm_obj_version_id                         AS version_id
            ,vco_obj_owner || ' => '
          || vco_obj_type || ' => '
          || vco_obj_name || ' => '
          || to_char(OVM_OBJ_VERSION_DATE, ORAVC_ENGINE.get_C_TOCHAR_DATEFORMAT) || ' => '
          || ovm_obj_version_id             AS version_Value
          ,ROW_NUMBER() OVER (PARTITION BY vco_obj_owner, vco_obj_type, vco_obj_name  ORDER BY OVM_OBJ_VERSION_DATE desc) AS version_number
      FROM oravc_obj_version
          ,oravc_obj
     WHERE vco_obj_vc_id = ovm_obj_vc_id
       AND (   length(p_filterobj) = 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || ';') > 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || C_FILTERID_CONNECTOR || vco_obj_type || ';')  > 0
            OR INSTR(p_filterobj, C_FILTERID_CONNECTOR || vco_obj_owner || C_FILTERID_CONNECTOR || vco_obj_type || C_FILTERID_CONNECTOR || vco_obj_name || ';')  > 0
       )
    ORDER BY vco_obj_owner, vco_obj_type, vco_obj_name, ovm_obj_version_id asc
  ) WHERE (p_filtervesrionscount < 1 OR version_number <= p_filtervesrionscount)
  ;

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  l_filterdays := TO_NUMBER(REPLACE(REPLACE(regexp_substr(p_filters, C_FILTERVERSIONSCOUNT || C_FILTERID_CONNECTOR || '.*?;',1,1), C_FILTERVERSIONSCOUNT || C_FILTERID_CONNECTOR), ';'));
  l_filterobj := REPLACE(p_filters, regexp_substr(p_filters, C_FILTERVERSIONSCOUNT || C_FILTERID_CONNECTOR || '.*?;',1,1), '');

  --dbms_lob.append(l_result, 'main::' || p_filters || '::');
  --dbms_lob.append(l_result, 'days::' || to_char(l_filterdays) || '::');
  --dbms_lob.append(l_result, 'obj::' || l_filterobj || '::');

  IF p_prefix IN ('tab2', 'tab4') THEN
    dbms_lob.append(l_result, '<tr>'                      || chr(10));
    dbms_lob.append(l_result, '<th>first version</th>'  || chr(10));
    dbms_lob.append(l_result, '<td>'        || chr(10));
    dbms_lob.append(l_result, '<select class="oravc_select" id=' || p_prefix || 'dd1_0>' || chr(10));
    dbms_lob.append(l_result, '<option id=NONE name=NONE value=0>NONE</option>'    || chr(10));

    FOR object_versions_rec IN object_versions_cur(l_filterdays, l_filterobj) LOOP
      dbms_lob.append(l_result, '<option '
                          || ' id='''    || object_versions_rec.version_id || ''''
                          || ' name='''  || object_versions_rec.version_id || ''''
                          || ' value=''' || object_versions_rec.version_id || ''''
                          || '>'
                          || object_versions_rec.version_value || '</option>'   || chr(10));
    END LOOP;

    dbms_lob.append(l_result, '</select>'     || chr(10));
    dbms_lob.append(l_result, '</td>'         || chr(10));
    dbms_lob.append(l_result, '</tr>'         || chr(10));
 END IF;


  dbms_lob.append(l_result, '<tr>'          || chr(10));

  IF p_prefix IN ('tab2', 'tab4') THEN
    dbms_lob.append(l_result, '<th>new version</th>'   || chr(10));
  ELSE
    dbms_lob.append(l_result, '<th>version</th>'        || chr(10));
  END IF;
  dbms_lob.append(l_result, '<td>'        || chr(10));

  dbms_lob.append(l_result, '<select class="oravc_select" id=' || p_prefix || 'dd2_0>'    || chr(10));
  dbms_lob.append(l_result, '<option id=ALL name=NONE value=0>NONE</option>'    || chr(10));
  FOR object_version_childs_rec IN object_version_childs_cur(l_filterdays, l_filterobj) LOOP
    dbms_lob.append(l_result, '<option '
                      || ' id=''' || object_version_childs_rec.version_id || ''''
                      || ' name=''' || object_version_childs_rec.version_id || ''''
                      || ' value=''' || object_version_childs_rec.version_id || ''''
                      || '>'
                      || object_version_childs_rec.version_value || '</option>'   || chr(10));
  END LOOP;

  dbms_lob.append(l_result, '</select>'   || chr(10));
  dbms_lob.append(l_result, '</td>'       || chr(10));

  dbms_lob.append(l_result, '</tr>'         || chr(10));

  RETURN l_result;
END showVersionsBar;

/*
<comments>
  <function>
    showVersionCompare
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function retunes CLOB with html tab to show version source code
  </description>

  <parameters>
    <IN>
      [p_tab]                     [html page tab number to display]                                                                       [NUMBER]      [NULL]
      [p_object_version]          [version controll obeject version id 1]                                                                 [VARCHAR2]    [0]
      [p_report_type]             [report type: 1 (all-in-on html), 2 (all-in-one clob), 3-side-by-side html), 4(side-by-side clob)]      [NUMBER]      [0]
      [p_filters]                 [filters that should be applyed]                                                                        [CLOB]        [NULL]
    </IN>
  </parameters>

  <version>
    [1.0] [01-10-2011] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showObjectsVersionForm(
           p_object_version             VARCHAR2 := NULL
          ,p_forceCompare               NUMBER   := 0
          ,p_report_type                NUMBER   := 0
          ,p_filters                    CLOB     := NULL
         ) RETURN CLOB IS

  l_result                              CLOB;
  l_source                              CLOB;
  l_prefix                              VARCHAR2(10) := 'tab1';
  l_function_name                       VARCHAR2(64) := 'showObjectsVersionForm';

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  dbms_lob.append(l_result, '<table id="oravc_submittable">'  || chr(10));
  dbms_lob.append(l_result, '<tr>'                    || chr(10));
  dbms_lob.append(l_result, REPLACE(REPLACE(showVersionsBar(l_prefix, p_filters), '<tr>',''),'</tr>',''));
  dbms_lob.append(l_result, '<td>'                    || chr(10));
  dbms_lob.append(l_result, '<INPUT class="oravc_button" TYPE="button" name="' || l_prefix || 'submitButton" value="Show source" onClick="oraVCsubmitformForTab1(''' || l_prefix || ''')"/>'         || chr(10));
  dbms_lob.append(l_result, '</td>'                                               || chr(10));
  dbms_lob.append(l_result, '</tr>'                                               || chr(10));
  dbms_lob.append(l_result, '</table>'                                            || chr(10));

  dbms_lob.append(l_result, '<table id="oravc_source_display">'  || chr(10));
  IF p_object_version IS NOT NULL AND p_object_version <> 0 THEN
    SELECT ovm_obj_source
      INTO l_source
      FROM oravc_obj_version_main
     WHERE ovm_obj_version_id = p_object_version;

    dbms_lob.append(l_result, '<tr>'                               || chr(10));
    dbms_lob.append(l_result, '<td>'                               || chr(10));
    dbms_lob.append(l_result, ORAVC_ENGINE.getClobForHTML(NVL(l_source, 'NO SOURCE CODE AVAILEBLE'), 'id="oravc_source_displaytable"') || chr(10));
    dbms_lob.append(l_result, '</td>'                                               || chr(10));
    dbms_lob.append(l_result, '</tr>'                                               || chr(10));
    dbms_lob.append(l_result, '</table>'                                            || chr(10));
  END IF;

  RETURN l_result;

EXCEPTION
  WHEN OTHERS THEN
    ORAVC_ENGINE.add2log(
       p_message_type    => ORAVC_ENGINE.get_C_ERROR
      ,p_message_text    => 'ERROR IN ' || C_PACKAGE_NAME || '.' || l_function_name || chr(10)
      || SQLCODE || chr(10) || l_function_name || chr(10)
      || '    ,p_object_version => '       || p_object_version        || chr(10)
      || '    ,p_forceCompare => '         || p_forceCompare          || chr(10)
      || '    ,p_report_type => '          || p_report_type           || chr(10)
      || SQLERRM
      ,p_message_place    => C_PACKAGE_NAME || '.' || l_function_name
      );
    RETURN SQLERRM || chr(10) || ' check Version Controll log ';

END showObjectsVersionForm;

/*
<comments>
  <function>
    showVersionCompare
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function retunes CLOB with html tab for two version of Version controll objects compare.
  </description>

  <parameters>
    <IN>
      [p_object_version]          [version controll obeject version id 1]                                                                 [VARCHAR2]    [NULL]
      [p_object_version_child]    [version controll obeject version id 2]                                                                 [VARCHAR2]    [NULL]
      [p_forceCompare]            [forces comparation of two version not from the same tree]                                              [NUMBER]      [0]
      [p_report_type]             [report type: 1 (all-in-on html), 2 (all-in-one clob), 3-side-by-side html), 4(side-by-side clob)]      [NUMBER]      [0]
      [p_filters]                 [filters that should be applyed]                                                                        [CLOB]        [NULL]
    </IN>
  </parameters>

  <version>
    [1.0] [01-10-2011] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showVersionCompare(
           p_object_version             VARCHAR2 := NULL
          ,p_object_version_child       VARCHAR2 := NULL
          ,p_forceCompare               NUMBER   := 0
          ,p_report_type                NUMBER   := 0
          ,p_filters                    CLOB     := NULL
         ) RETURN CLOB IS

  l_result                              CLOB;
  l_prefix                              VARCHAR2(10) := 'tab2';
  l_function_name                       VARCHAR2(64) := 'showVersionCompare';
  l_versions_diff                       CLOB;

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  dbms_lob.append(l_result, '<table id="oravc_submittable">'  || chr(10));
  dbms_lob.append(l_result, showVersionsBar(l_prefix, p_filters));

  dbms_lob.append(l_result, '<tr>'                    || chr(10));
  dbms_lob.append(l_result, '<th>report type</th>'                                || chr(10));
  dbms_lob.append(l_result, '<td>'                    || chr(10));
  dbms_lob.append(l_result, '<p>'                                                || chr(10));
  dbms_lob.append(l_result, '<select class="oravc_select" id="' || l_prefix || 'reportType" name="'         || l_prefix || 'reportType">'        || chr(10));
  dbms_lob.append(l_result, '<option value=1 selected="selected">all-in-one HTML</option>'        || chr(10));
  dbms_lob.append(l_result, '<option value=7>all-in-one only changes HTML</option>'    || chr(10));
  dbms_lob.append(l_result, '<option value=2>all-in-one plane text</option>'           || chr(10));
  dbms_lob.append(l_result, '<option value=3>side-by-side HTML</option>'               || chr(10));
  dbms_lob.append(l_result, '<option value=4>side-by-side plane text</option>'         || chr(10));
  dbms_lob.append(l_result, '</select>'                                                || chr(10));
  IF p_forceCompare = 1 THEN
    dbms_lob.append(l_result, '<input class="oravc_checkbox" type="checkbox" id="' || l_prefix || 'forceCompare" name="' || l_prefix || 'forceCompare" checked/>force compare of ONLY two objects'  || chr(10));
  ELSE
    dbms_lob.append(l_result, '<input class="oravc_checkbox" type="checkbox" id="' || l_prefix || 'forceCompare" name="' || l_prefix || 'forceCompare" />force compare of ONLY two objects'         || chr(10));
  END IF;
  dbms_lob.append(l_result, '<INPUT class="oravc_button" TYPE="button" name="' || l_prefix || 'submitButton" value="Build report" onClick="oraVCsubmitformForTab2(''' || l_prefix || ''')"/>'         || chr(10));
  dbms_lob.append(l_result, '</p>'                                                || chr(10));
  dbms_lob.append(l_result, '</td>'                                               || chr(10));
  dbms_lob.append(l_result, '</tr>'                                               || chr(10));


  dbms_lob.append(l_result, '<tr>'                    || chr(10));
  dbms_lob.append(l_result, '<td>'                    || chr(10));
  dbms_lob.append(l_result, '<br>'                    || chr(10));
  dbms_lob.append(l_result, '</td>'                                               || chr(10));
  dbms_lob.append(l_result, '</tr>'                                               || chr(10));

  dbms_lob.append(l_result, '</table>'                                            || chr(10));

  IF (    p_object_version IS NOT NULL
      AND p_object_version  > 0
      AND p_object_version_child IS NOT NULL
      AND p_object_version_child > 0
     ) THEN
    CASE
      WHEN p_report_type = 1 THEN
        dbms_lob.append(l_result, ORAVC_ENGINE.allINone_diff_htmlTable(p_object_version, p_object_version_child, p_forceCompare, 0, 0));

      WHEN p_report_type = 7 THEN
        dbms_lob.append(l_result, ORAVC_ENGINE.allINone_diff_htmlTable(p_object_version, p_object_version_child, p_forceCompare, 1, 0));

      WHEN p_report_type = 2 THEN
        dbms_lob.append(l_result, ORAVC_ENGINE.getClobForHTML( ORAVC_ENGINE.allINone_diff_clob(p_object_version, p_object_version_child, p_forceCompare), 'id="oravc_source_displaytable"' ));

      WHEN p_report_type = 3 THEN
        dbms_lob.append(l_result, ORAVC_ENGINE.sideBYside_diff_htmlTable(p_object_version, p_object_version_child, p_forceCompare));

      WHEN p_report_type = 4 THEN
        dbms_lob.append(l_result, ORAVC_ENGINE.getClobForHTML( ORAVC_ENGINE.sideBYside_diff_clob(p_object_version, p_object_version_child, p_forceCompare), 'id="oravc_source_displaytable"'));

      ELSE
        NULL;
    END CASE;
  END IF;

  RETURN l_result;

EXCEPTION
  WHEN OTHERS THEN
    ORAVC_ENGINE.add2log(
       p_message_type    => ORAVC_ENGINE.get_C_ERROR
      ,p_message_text    => 'ERROR IN ' || C_PACKAGE_NAME || '.' || l_function_name || chr(10)
      || SQLCODE || chr(10) || l_function_name || chr(10)
      || '    ,p_object_version => '       || p_object_version        || chr(10)
      || '    ,p_object_version_child => ' || p_object_version_child  || chr(10)
      || '    ,p_forceCompare => '         || p_forceCompare          || chr(10)
      || '    ,p_report_type => '          || p_report_type           || chr(10)
      || '    ,p_filters => '              || p_filters               || chr(10)
      || SQLERRM
      ,p_message_place    => C_PACKAGE_NAME || '.' || l_function_name
      );
    RETURN SQLERRM || chr(10) || ' check Version Controll log ';
END showVersionCompare;


/*
<comments>
  <function>
    showVersionGenerator
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function retunes CLOB with html tab for source code generator of from versions of Version controll objects compare.
  </description>

  <parameters>
    <IN>
      [p_object_version]          [version controll obeject version id 1]                     [VARCHAR2]    [NULL]
      [p_object_version_child]    [version controll obeject version id 2]                     [VARCHAR2]    [NULL]
      [p_forceCompare]            [forces comparation of two version not from the same tree]  [NUMBER]      [0]
      [p_filters]                 [filters that should be applyed]                            [CLOB]        [NULL]
    </IN>
  </parameters>

  <version>
    [1.0] [01-03-2012] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showVersionGenerator(
           p_object_version             VARCHAR2 := NULL
          ,p_object_version_child       VARCHAR2 := NULL
          ,p_forceCompare               NUMBER   := 0
          ,p_filters                    CLOB     := NULL
         ) RETURN CLOB IS

  l_result                              CLOB;
  l_prefix                              VARCHAR2(10) := 'tab4';
  l_function_name                       VARCHAR2(64) := 'showVersionGenerator';
  l_versions_diff                       CLOB;

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  dbms_lob.append(l_result, '<table id="oravc_submittable">'  || chr(10));
  dbms_lob.append(l_result, showVersionsBar(l_prefix, p_filters));

  dbms_lob.append(l_result, '<tr>'                    || chr(10));
  dbms_lob.append(l_result, '<th></th>'               || chr(10));
  dbms_lob.append(l_result, '<td>'                    || chr(10));

  dbms_lob.append(l_result, '<p>'                                                || chr(10));
  IF p_forceCompare = 1 THEN
    dbms_lob.append(l_result, '<input class="oravc_checkbox" type="checkbox" id="' || l_prefix || 'forceCompare" name="' || l_prefix || 'forceCompare" checked/>force compare of ONLY two objects'  || chr(10));
  ELSE
    dbms_lob.append(l_result, '<input class="oravc_checkbox" type="checkbox" id="' || l_prefix || 'forceCompare" name="' || l_prefix || 'forceCompare" />force compare of ONLY two objects'         || chr(10));
  END IF;
  dbms_lob.append(l_result, '<INPUT class="oravc_button" TYPE="button" name="' || l_prefix || 'submitButton" value="Build source table" onClick="oraVCsubmitformForTab4(''' || l_prefix || ''')"/>'         || chr(10));
  dbms_lob.append(l_result, '</p>'                                                || chr(10));
  dbms_lob.append(l_result, '</td>'                                               || chr(10));
  dbms_lob.append(l_result, '</tr>'                                               || chr(10));


  dbms_lob.append(l_result, '<tr>'                    || chr(10));
  dbms_lob.append(l_result, '<td>'                    || chr(10));
  dbms_lob.append(l_result, '<br>'                    || chr(10));
  dbms_lob.append(l_result, '</td>'                                               || chr(10));
  dbms_lob.append(l_result, '</tr>'                                               || chr(10));

  dbms_lob.append(l_result, '</table>'                                            || chr(10));

  IF (    p_object_version IS NOT NULL
      AND p_object_version  > 0
      AND p_object_version_child IS NOT NULL
      AND p_object_version_child > 0
     ) THEN
    dbms_lob.append(l_result, ORAVC_ENGINE.allINone_diff_htmlTable(p_object_version, p_object_version_child, p_forceCompare, 0, 1));
  END IF;

  RETURN l_result;
EXCEPTION
  WHEN OTHERS THEN
    ORAVC_ENGINE.add2log(
       p_message_type    => ORAVC_ENGINE.get_C_ERROR
      ,p_message_text    => 'ERROR IN ' || C_PACKAGE_NAME || '.' || l_function_name || chr(10)
      || SQLCODE || chr(10) || l_function_name || chr(10)
      || '    ,p_object_version => '       || p_object_version        || chr(10)
      || '    ,p_object_version_child => ' || p_object_version_child  || chr(10)
      || '    ,p_forceCompare => '         || p_forceCompare          || chr(10)
      || SQLERRM
      ,p_message_place    => C_PACKAGE_NAME || '.' || l_function_name
      );
    RETURN SQLERRM || chr(10) || ' check Version Controll log ';

END showVersionGenerator;

/*
<comments>
  <function>
    showLog
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function retunes CLOB with Log messages display html tab
  </description>

  <parameters>
    <IN>
      [p_logs_to_display]         [how many log messages to display (default 50)]    [NUMBER]   [NULL]
    </IN>
  </parameters>

  <version>
    [1.0] [01-10-2011] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showLog(
           p_logs_to_display            NUMBER   := NULL
         ) RETURN CLOB IS
  l_result                              CLOB         := NULL;
  l_prefix                              VARCHAR2(10) := 'tab5';
  l_function_name                       VARCHAR2(64) := 'showLog';
  l_bgcolor                             VARCHAR2(255);

  CURSOR log_cur IS
    SELECT  ROWNUM rn
           ,vcl_id
           ,to_char(vcl_datetime, ORAVC_ENGINE.get_C_TOCHAR_DATEFORMAT) log_date
           ,vcl_message_type
           ,vcl_message_text
           ,vcl_message_place
      FROM (SELECT *
              FROM oravc_log
            ORDER BY 1 DESC
           )
     WHERE ROWNUM <= NVL(p_logs_to_display, 50);

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  dbms_lob.append(l_result, '<table class="oravc_submittable">'  || chr(10));
  dbms_lob.append(l_result, '<tr>'                   || chr(10));
  dbms_lob.append(l_result, '<td>'                   || chr(10));
  dbms_lob.append(l_result, '<label>Log messages count<label>'                    || chr(10));
  dbms_lob.append(l_result, '<input type="text" id="' || l_prefix || 'logsmToDisplay" name="' || l_prefix || 'logsmToDisplay" value="' || TO_CHAR(p_logs_to_display) || '"></input>'  || chr(10));
  dbms_lob.append(l_result, '</td>'                                               || chr(10));
  dbms_lob.append(l_result, '<td>'                   || chr(10));
  dbms_lob.append(l_result, '<INPUT class="oravc_button" TYPE="button" name="' || l_prefix || 'submitButton" value="Show log" onClick="oraVCsubmitformForTab5(''' || l_prefix || ''')"/>'         || chr(10));
  dbms_lob.append(l_result, '</td>'                                               || chr(10));
  dbms_lob.append(l_result, '</tr>'                                               || chr(10));
  dbms_lob.append(l_result, '</table>'                                            || chr(10));

  dbms_lob.append(l_result, '<table id="oravc_log_displaytable">'  || chr(10));
  dbms_lob.append(l_result, '<tr>'                               || chr(10));
  dbms_lob.append(l_result, '<th></th>'                       || chr(10));
  dbms_lob.append(l_result, '<th>Time</th>'                   || chr(10));
  dbms_lob.append(l_result, '<th>Type</th>'                   || chr(10));
  dbms_lob.append(l_result, '<th>Place</th>'                  || chr(10));
  dbms_lob.append(l_result, '<th>Message</th>'                || chr(10));
  dbms_lob.append(l_result, '</tr>'                                               || chr(10));

  FOR log_rec IN log_cur LOOP
    CASE
      WHEN log_rec.vcl_message_type = ORAVC_ENGINE.get_C_ERROR THEN
        l_bgcolor := ORAVC_ENGINE.get_C_DELETED;
      WHEN log_rec.vcl_message_type = ORAVC_ENGINE.get_C_WARNING THEN
        l_bgcolor := ORAVC_ENGINE.get_C_ADDED;
      ELSE
        l_bgcolor := ORAVC_ENGINE.get_C_UNCHANGED;
    END CASE;

    dbms_lob.append(l_result, '<tr class="oravc_tr' || l_bgcolor || '">'                        || chr(10));
    dbms_lob.append(l_result, '<td>'               || chr(10));
    dbms_lob.append(l_result, log_rec.rn                                                        || chr(10));
    dbms_lob.append(l_result, '</td>'                                                           || chr(10));
    dbms_lob.append(l_result, '<td>'               || chr(10));
    dbms_lob.append(l_result, log_rec.log_date                                                  || chr(10));
    dbms_lob.append(l_result, '</td>'                                                           || chr(10));
    dbms_lob.append(l_result, '<td>'               || chr(10));
    dbms_lob.append(l_result, log_rec.vcl_message_type                                          || chr(10));
    dbms_lob.append(l_result, '</td>'                                                           || chr(10));
    dbms_lob.append(l_result, '<td>'               || chr(10));
    dbms_lob.append(l_result, log_rec.vcl_message_place                                         || chr(10));
    dbms_lob.append(l_result, '</td>'                                                           || chr(10));
    dbms_lob.append(l_result, '<td>'               || chr(10));
    dbms_lob.append(l_result, ORAVC_ENGINE.replaceHTMLspecialChars(log_rec.vcl_message_text)    || chr(10));
    dbms_lob.append(l_result, '</td>'                                                           || chr(10));
    dbms_lob.append(l_result, '</tr>'                                                           || chr(10));
  END LOOP;
  dbms_lob.append(l_result, '</table>'                                                          || chr(10));

  RETURN l_result;

EXCEPTION
  WHEN OTHERS THEN
    ORAVC_ENGINE.add2log(
       p_message_type    => ORAVC_ENGINE.get_C_ERROR
      ,p_message_text    => 'ERROR IN ' || C_PACKAGE_NAME || '.' || l_function_name || chr(10)
      || SQLCODE || chr(10) || l_function_name || chr(10)
      || '    ,p_logs_to_display => '          || p_logs_to_display                 || chr(10)
      || SQLERRM
      ,p_message_place    => C_PACKAGE_NAME || '.' || l_function_name
      );
    RETURN SQLERRM || chr(10) || ' check Version Controll log ';

END showLog;

/*
<comments>
  <function>
    showORAVC_API
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function returnes CLOB with description of ORAVC API in HTML format
  </description>

  <version>
    [1.0] [01-03-2012] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showORAVC_API RETURN CLOB IS
    l_result                              CLOB         := NULL;
  l_function_name                       VARCHAR2(64) := 'showORAVC_API';

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);

  dbms_lob.append(l_result, addAdminOptionsTable);

  dbms_lob.append(l_result, '<table id="oravc_api_displaytable">'   || chr(10));
  dbms_lob.append(l_result, '<tr>'                                  || chr(10));
  dbms_lob.append(l_result, '<td>'                                  || chr(10));
  dbms_lob.append(l_result, ORATSG_APIDOC.getORAVC_API_HTMLDocHeader(
                                 oratsg_apidoc.T_CLOB_ARRAY('obj1', 'obj2', 'obj3', 'obj4', 'obj5')
                                ,oratsg_apidoc.T_CLOB_ARRAY(
                                    SYS_CONTEXT('USERENV', 'CURRENT_USER') || '.ORAVC_ENGINE'
                                   ,SYS_CONTEXT('USERENV', 'CURRENT_USER') || '.ORAVC_ENGINE_WEB'
                                   ,SYS_CONTEXT('USERENV', 'CURRENT_USER') || '.ORAVC_JOB'
                                   ,SYS_CONTEXT('USERENV', 'CURRENT_USER') || '.ORAVC_TRIGGER'
                                   ,SYS_CONTEXT('USERENV', 'CURRENT_USER') || '.ORATSG_APIDOC')
                                   )
                            );
  dbms_lob.append(l_result, '</td>'                                 || chr(10));
  dbms_lob.append(l_result, '</tr>'                                 || chr(10));
  dbms_lob.append(l_result, '<tr>'                                  || chr(10));
  dbms_lob.append(l_result, '<td>'                                  || chr(10));
  dbms_lob.append(l_result, ORATSG_APIDOC.getORAVC_API_HTMLDoc(SYS_CONTEXT('USERENV', 'CURRENT_USER'), 'PACKAGE', 'ORAVC_ENGINE', 'obj1'));
  dbms_lob.append(l_result, '</td>'                                 || chr(10));
  dbms_lob.append(l_result, '</tr>'                                 || chr(10));
  dbms_lob.append(l_result, '<tr>'                                  || chr(10));
  dbms_lob.append(l_result, '<td>'                                  || chr(10));
  dbms_lob.append(l_result, ORATSG_APIDOC.getORAVC_API_HTMLDoc(SYS_CONTEXT('USERENV', 'CURRENT_USER'), 'PACKAGE', 'ORAVC_ENGINE_WEB', 'obj2'));
  dbms_lob.append(l_result, '</td>'                                 || chr(10));
  dbms_lob.append(l_result, '</tr>'                                 || chr(10));
  dbms_lob.append(l_result, '<tr>'                                  || chr(10));
  dbms_lob.append(l_result, '<td>'                                  || chr(10));
  dbms_lob.append(l_result, ORATSG_APIDOC.getORAVC_API_HTMLDoc(SYS_CONTEXT('USERENV', 'CURRENT_USER'), 'PACKAGE', 'ORAVC_JOB', 'obj3'));
  dbms_lob.append(l_result, '</td>'                                 || chr(10));
  dbms_lob.append(l_result, '</tr>'                                 || chr(10));
  dbms_lob.append(l_result, '<tr>'                                  || chr(10));
  dbms_lob.append(l_result, '<td>'                                  || chr(10));
  dbms_lob.append(l_result, ORATSG_APIDOC.getORAVC_API_HTMLDoc(SYS_CONTEXT('USERENV', 'CURRENT_USER'), 'PACKAGE', 'ORAVC_TRIGGER', 'obj4'));
  dbms_lob.append(l_result, '</td>'                                 || chr(10));
  dbms_lob.append(l_result, '</tr>'                                 || chr(10));
  dbms_lob.append(l_result, '<tr>'                                  || chr(10));
  dbms_lob.append(l_result, '<td>'                                  || chr(10));
  dbms_lob.append(l_result, ORATSG_APIDOC.getORAVC_API_HTMLDoc(SYS_CONTEXT('USERENV', 'CURRENT_USER'), 'PACKAGE', 'ORATSG_APIDOC', 'obj5'));
  dbms_lob.append(l_result, '</td>'                                 || chr(10));
  dbms_lob.append(l_result, '</tr>'                                 || chr(10));
  dbms_lob.append(l_result, '</table>'                              || chr(10));


  RETURN l_result;

EXCEPTION
  WHEN OTHERS THEN
    ORAVC_ENGINE.add2log(
       p_message_type    => ORAVC_ENGINE.get_C_ERROR
      ,p_message_text    => 'ERROR IN ' || C_PACKAGE_NAME || '.' || l_function_name || chr(10)
      || SQLCODE || chr(10) || l_function_name || chr(10)
      || SQLERRM
      ,p_message_place    => C_PACKAGE_NAME || '.' || l_function_name
      );
    RETURN SQLERRM || chr(10) || ' check Version Controll log ';

END showORAVC_API;


/*
<comments>
  <function>
    showAdminInfo
  </function>

  <return>
    CLOB
  </return>

  <description>
    Function returnes Information For Administrators about status of OraVC setup
  </description>

  <version>
    [1.0] [22-23-2013] [Andrey Tsyganov] [creation] []
  </version>

</comments>
*/
FUNCTION showAdminInfo RETURN CLOB IS
  l_result                              CLOB         := NULL;
  l_function_name                       VARCHAR2(64) := 'showAdminInfo';
  l_count                               NUMBER       := 0;

  CURSOR oravc_job_cur IS
    SELECT JOB_NAME
          ,STATE
          ,to_char(LAST_START_DATE, C_TOCHAR_DATEFORMAT)   last_start_date
          ,to_char(LAST_RUN_DURATION) last_run_duration
          ,to_char(NEXT_RUN_DATE, C_TOCHAR_DATEFORMAT)     next_run_date
      FROM user_SCHEDULER_JOBS
     WHERE JOB_NAME = ORAVC_JOB.get_C_ORAVC_REFRESH_JOB;

  CURSOR oravc_users_to_monitor_cur IS
    SELECT vc_ora_user
      FROM oravc_usr2monitor;

  CURSOR oravc_objtypes_to_monitor_cur IS
    SELECT vc_ora_objtype
      FROM oravc_objtype2monitor;

  CURSOR oravc_ddlev_to_monitor_cur IS
    SELECT vc_ora_event
      FROM oravc_event2monitor;


  CURSOR oravc_last50_trgevents_cur IS
    SELECT oot_record_id
          ,oot_event
          ,oot_eventtime
          ,oot_objowner
          ,oot_objname
          ,oot_objtype
          ,SUBSTR(oot_objversioninfo, 1, 200) || '...' as oot_objversioninfo
      FROM (
        SELECT *
          FROM oravc_obj_trgchanges
         ORDER BY oot_eventtime desc
        )
      WHERE ROWNUM < 51
    ;

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  dbms_lob.append(l_result, '<table id="oravc_api_displaytable">' || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>OraVC Job status</th>'           || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));

  SELECT COUNT(*)
    INTO l_count
    FROM user_SCHEDULER_JOBS
   WHERE JOB_NAME = ORAVC_JOB.get_C_ORAVC_REFRESH_JOB;

  IF l_count = 0 THEN
    dbms_lob.append(l_result, '<tr>'                                || chr(10));
    dbms_lob.append(l_result, '<td>Ora VC job is not started. Repository might be not up to date (Check OraVC API for the Job start command)</td>'        || chr(10));
    dbms_lob.append(l_result, '</tr>'                               || chr(10));

  ELSE
    dbms_lob.append(l_result, '<tr>'                                || chr(10));
    dbms_lob.append(l_result, '<th>Job Name</th>'        || chr(10));
    dbms_lob.append(l_result, '<th>Job State</th>'        || chr(10));
    dbms_lob.append(l_result, '<th>Last start date</th>'        || chr(10));
    dbms_lob.append(l_result, '<th>Last run duration</th>'        || chr(10));
    dbms_lob.append(l_result, '<th>Next run date</th>'        || chr(10));
    dbms_lob.append(l_result, '</tr>'                               || chr(10));
    FOR oravc_job_rec IN oravc_job_cur LOOP
      dbms_lob.append(l_result, '<tr>'                                        || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_job_rec.JOB_NAME           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_job_rec.STATE              || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_job_rec.last_start_date    || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_job_rec.last_run_duration  || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_job_rec.next_run_date      || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '</tr>'                                       || chr(10));
    END LOOP;
  END IF;

  dbms_lob.append(l_result, '<tr><td><br></td><tr>'                                || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Users included into OraVC processing </th>'           || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));
  FOR oravc_users_to_monitor_rec IN oravc_users_to_monitor_cur LOOP
      dbms_lob.append(l_result, '<tr>'                                        || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_users_to_monitor_rec.vc_ora_user           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '</tr>'                                       || chr(10));
  END LOOP;

  dbms_lob.append(l_result, '<tr><td><br></td><tr>'                                || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Object types included into OraVC processing </th>'           || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));
  FOR oravc_objtypes_to_monitor_rec IN oravc_objtypes_to_monitor_cur LOOP
      dbms_lob.append(l_result, '<tr>'                                        || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_objtypes_to_monitor_rec.vc_ora_objtype           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '</tr>'                                       || chr(10));
  END LOOP;

  dbms_lob.append(l_result, '<tr><td><br></td><tr>'                                || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>DDL events included into OraVC processing </th>'           || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));
  FOR oravc_ddlev_to_monitor_rec IN oravc_ddlev_to_monitor_cur LOOP
      dbms_lob.append(l_result, '<tr>'                                        || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_ddlev_to_monitor_rec.vc_ora_event           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '</tr>'                                       || chr(10));
  END LOOP;

  SELECT count(*)
    INTO l_count
    FROM oravc_obj_trgchanges;

  dbms_lob.append(l_result, '</table>'                            || chr(10));
  dbms_lob.append(l_result, '<br>'                                || chr(10));

  dbms_lob.append(l_result, '<table id="oravc_log_displaytable">' || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th> The last 50 unprocessed events from the triggers</th>' || chr(10));
  dbms_lob.append(l_result, '<th colspan=5> The total number of unprocessed events: ' || to_char(l_count) || '</th>' || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));
  dbms_lob.append(l_result, '<tr>'                                || chr(10));
  dbms_lob.append(l_result, '<th>Event info </th>'           || chr(10));
  dbms_lob.append(l_result, '<th>Event </th>'           || chr(10));
  dbms_lob.append(l_result, '<th>Time</th>'           || chr(10));
  dbms_lob.append(l_result, '<th>Type</th>'           || chr(10));
  dbms_lob.append(l_result, '<th>Owner</th>'           || chr(10));
  dbms_lob.append(l_result, '<th>Name</th>'           || chr(10));
  dbms_lob.append(l_result, '</tr>'                               || chr(10));
  FOR oravc_last50_trgevents_rec IN oravc_last50_trgevents_cur LOOP
      dbms_lob.append(l_result, '<tr>'                                        || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_last50_trgevents_rec.oot_objversioninfo           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_last50_trgevents_rec.oot_event           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || to_char(oravc_last50_trgevents_rec.oot_eventtime,'dd.mm.yyyy HH24:MI:SS') || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_last50_trgevents_rec.oot_objtype           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_last50_trgevents_rec.oot_objowner           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '<td>' || oravc_last50_trgevents_rec.oot_objname           || '</td>'                                || chr(10));
      dbms_lob.append(l_result, '</tr>'                                       || chr(10));
  END LOOP;
  dbms_lob.append(l_result, '</table>'                            || chr(10));
  dbms_lob.append(l_result, '<br>'                                || chr(10));
  dbms_lob.append(l_result, addAdminOptionsTable);

  RETURN l_result;

END showAdminInfo;

/*
<comments>
  in package specification

</comments>
*/
FUNCTION oravc_webInfo(
           p_base_url                   VARCHAR2
          ,p_tab                        NUMBER
          ,p_tab_prev                   NUMBER
          ,p_object_version             VARCHAR2
          ,p_object_version_child       VARCHAR2
          ,p_filters                    CLOB
          ,p_forceCompare               NUMBER
          ,p_report_type                NUMBER
          ,p_logs_to_display            NUMBER
          ,p_custom_css                 CLOB      := G_CSS_FIXED
          ,p_show_title                 NUMBER    := 0
          ,p_show_menu_admininfo        NUMBER    := 0
          ,p_show_menu_filter           NUMBER    := 0
          ,p_show_menu_oravclog         NUMBER    := 0
          ,p_show_menu_objectversion    NUMBER    := 0
          ,p_show_menu_versioncompare   NUMBER    := 0
          ,p_show_menu_versiongenerate  NUMBER    := 0
          ,p_show_menu_oravcapi         NUMBER    := 0
          ) RETURN CLOB IS
  l_result                              CLOB            := NULL;
  l_base_url                            VARCHAR2(4000)  := CASE WHEN p_base_url = G_BASE_URI THEN
                                                                  formatClobToJavascriptString(p_base_url)              
                                                                ELSE
                                                                  '"' ||  formatClobToJavascriptString(p_base_url) || '"'
                                                           END;
  l_clob                                CLOB            := NULL;
  l_filters                             CLOB            := CASE WHEN p_filters IS NULL OR length(p_filters) = 0 THEN
                                                             C_FILTERVERSIONSCOUNT || C_FILTERID_CONNECTOR || C_DEF_FILTERVERSIONSCOUNT || ';'
                                                           ELSE
                                                             REPLACE(REPLACE(p_filters, chr(10), ''), chr(13), '')
                                                           END;
  --NULL; --REPLACE(REPLACE(NVL(p_filters, ''), chr(10), ''), chr(13), '');
  l_tab                                 NUMBER          := NVL(p_tab, 0);
  l_tab_prev                            NUMBER          := NVL(p_tab_prev, 2);
  l_forceCompare                        NUMBER          := NVL(p_forceCompare, 0);
  l_report_type                         NUMBER          := NVL(p_report_type, 0);
  l_logs_to_display                     NUMBER          := NVL(p_logs_to_display, 50);
  l_function_name                       VARCHAR2(64)    := 'oravc_webInfo';
  l_db_name                             VARCHAR2(256)   := 'l_db_name';
  l_afterPageLoadJavaScript             CLOB            :=
  '
  function createMainSubmitFormElements(p_form) {

    var el1 = document.createElement("input"); 
    el1.setAttribute("type","hidden");
    el1.setAttribute("id","p_tab");
    el1.setAttribute("name","p_tab");
        
    var el2 = document.createElement("input"); 
    el2.setAttribute("type","hidden");
    el2.setAttribute("id","p_tab_prev");
    el2.setAttribute("name","p_tab_prev");

    var el3 = document.createElement("input"); 
    el3.setAttribute("type","hidden");
    el3.setAttribute("id","p_object_version");
    el3.setAttribute("name","p_object_version");

    var el4 = document.createElement("input"); 
    el4.setAttribute("type","hidden");
    el4.setAttribute("id","p_object_version_child");
    el4.setAttribute("name","p_object_version_child");

    var el5 = document.createElement("input"); 
    el5.setAttribute("type","hidden");
    el5.setAttribute("id","p_filters");
    el5.setAttribute("name","p_filters");

    var el6 = document.createElement("input"); 
    el6.setAttribute("type","hidden");
    el6.setAttribute("id","p_forceCompare");
    el6.setAttribute("name","p_forceCompare");

    var el7 = document.createElement("input"); 
    el7.setAttribute("type","hidden");
    el7.setAttribute("id","p_report_type");
    el7.setAttribute("name","p_report_type");

    var el8 = document.createElement("input"); 
    el8.setAttribute("type","hidden");
    el8.setAttribute("id","p_logs_to_display");
    el8.setAttribute("name","p_logs_to_display");
       
    p_form.appendChild(el1);
    p_form.appendChild(el2);
    p_form.appendChild(el3);
    p_form.appendChild(el4);
    p_form.appendChild(el5);
    p_form.appendChild(el6);
    p_form.appendChild(el7);
    p_form.appendChild(el8);

    document.getElementsByTagName("body")[0].appendChild(p_form);

  }
  
  function createMainSubmitForm() {
    var f = document.createElement("form");
    f.setAttribute("method","POST");
    f.setAttribute("id","oraVCsubmitForm");
    f.setAttribute("name","oraVCsubmitForm");
    f.setAttribute("action", ' || l_base_url || ');
  
    createMainSubmitFormElements(f);
  }

  function afterPageLoad(pprefix) {
    createMainSubmitForm();
    /*
    if (pprefix == ''tab1'' || pprefix == ''tab2'' || pprefix == ''tab4'' ) {
      document.getElementById(pprefix+"dd2_0").value       = ''' || formatClobToJavascriptString(NVL(p_object_version_child, 'NONE')) || ''';
      if (pprefix == ''tab2'' || pprefix == ''tab4'') {
        document.getElementById(pprefix+"dd1_0").value            = ''' || formatClobToJavascriptString(NVL(p_object_version, 'NONE')) || ''';
        document.getElementById(pprefix + "forceCompare").checked = ' || CASE WHEN p_forceCompare = 1 THEN 'true' ELSE 'false' END ||';
     }
    }

    if (pprefix == ''tab2'' || pprefix == ''tab3'') {
      document.getElementById(pprefix+"reportType").value  = ' || formatClobToJavascriptString(to_char(NVL(p_report_type, 0))) || ';
    }

    document.oraVCsubmitForm.p_filters.value = "' || formatClobToJavascriptString(l_filters) || '";
    if (pprefix == ''tab7'') {
      var filters = document.oraVCsubmitForm.p_filters.value.split(";");
      var filterCheckBox;
      var tmp;
      for (var i = 0; i < filters.length; i++) {
          tmp = filters[i].split("' || C_FILTERID_CONNECTOR || '");
          if (tmp[0] == "' || C_FILTERVERSIONSCOUNT || '")
            document.getElementById("' || C_FILTERVERSIONSCOUNT || '").value = tmp[1];
          else
            filterCheckBox = document.getElementById("filterCheckBox" + filters[i]);
            if (filterCheckBox != null)
              filterCheckBox.checked = true;
      }
    }

    document.oraVCsubmitForm.p_tab_prev.value = "' || formatClobToJavascriptString(to_char(p_tab)) || '";
  */
  }
  ';

BEGIN
  dbms_lob.createtemporary(l_result, TRUE);
  --dbms_lob.append(l_result, htf.htmlOpen);
  --dbms_lob.append(l_result, htf.headOpen);

  IF p_custom_css IS NULL OR length(p_custom_css) = 0 OR p_custom_css = G_CSS_STATIC THEN
    -- if custom CSS was not sent, then using default one
    dbms_lob.append(l_result, '<style type="text/css">' || chr(10) || REPLACE(G_WEBFORM_DEFAULT_CSS, C_CSS_MENU_TAG, G_CSS_STATIC) || chr(10) || '</style>' || chr(10));
  ELSIF p_custom_css = G_CSS_FIXED THEN
    dbms_lob.append(l_result, '<style type="text/css">' || chr(10) || REPLACE(G_WEBFORM_DEFAULT_CSS, C_CSS_MENU_TAG, G_CSS_FIXED) || chr(10) || '</style>' || chr(10));
  ELSIF p_custom_css IN (G_CSS_NO_CSS1, G_CSS_NO_CSS2) THEN
    dbms_lob.append(l_result, ' ');
  ELSE
    dbms_lob.append(l_result, p_custom_css);
  END IF;

  dbms_lob.append(l_result, '<script type="text/javascript">' || chr(10) || G_WEBFORM_JAVASCRIPT || chr(10) || l_afterPageLoadJavaScript || chr(10) || '</script>'|| chr(10));

  --dbms_lob.append(l_result, l_filters);
  -- please wait div
  dbms_lob.append(l_result, '<div id="waiting-overlay" class="oravc_please_wait"><table height=100% width=100%><tr><td align=right valign=top>><h2><font color="red">Loading... Please wait...</font></h2></td></tr></table></div>');
  --IF p_custom_css NOT IN (G_CSS_NO_CSS1, G_CSS_NO_CSS2) THEN
  --  dbms_lob.append(l_result, '<div id="waiting-overlay" class="oravc_please_wait"><table height=100% width=100%><tr><td align=right valign=top>><h2><font color="red">Loading... Please wait...</font></h2></td></tr></table></div>');
  --END IF;

  IF 0 IN (p_show_title
          ,p_show_menu_admininfo
          ,p_show_menu_filter
          ,p_show_menu_oravclog
          ,p_show_menu_objectversion
          ,p_show_menu_versioncompare
          ,p_show_menu_versiongenerate
          ,p_show_menu_oravcapi
         ) THEN
    dbms_lob.append(l_result, '<div id="oravc_menu-50"><br><br><div>' || chr(10));
    dbms_lob.append(l_result, '<div id="oravc_menu0">' || chr(10));
    dbms_lob.append(l_result, '<div id="oravc_menu">' || chr(10));
  END IF;

  dbms_lob.append(l_result, '<ul>'                                || chr(10));
  IF p_show_title = 0 THEN
    SELECT sys_context('USERENV', 'DB_NAME')
      INTO l_db_name
      FROM DUAL;
    dbms_lob.append(l_result, '<li class="textli">OraVC data viewer<font color="#a12828"> (<i>' || l_db_name || '</i>)</font></li>'   || chr(10));
  END IF;



  IF p_show_menu_admininfo = 0 THEN
    dbms_lob.append(l_result, '<li>'                                || chr(10));
    IF l_tab = 0 THEN
      dbms_lob.append(l_result, '<A class="active" HREF="javascript:oraVCsubmitformGeneral(0);"' || '">');
    ELSE
      dbms_lob.append(l_result, '<A HREF="javascript:oraVCsubmitformGeneral(0);"' || '">');
    END IF;
    dbms_lob.append(l_result, 'Admin');
    dbms_lob.append(l_result, '</A>'                                || chr(10));
    dbms_lob.append(l_result, '</li>'                               || chr(10));
  END IF;

  IF p_show_menu_filter = 0 THEN
    dbms_lob.append(l_result, '<li>'                                || chr(10));
    IF l_tab = 7 THEN
      dbms_lob.append(l_result, '<A class="active" HREF="javascript:oraVCsubmitformGeneral(7);"' || '">');
    ELSE
      dbms_lob.append(l_result, '<A HREF="javascript:oraVCsubmitformGeneral(7);"' || '">');
    END IF;
    dbms_lob.append(l_result, 'Filter');
    dbms_lob.append(l_result, '</A>'                                || chr(10));
    dbms_lob.append(l_result, '</li>'                               || chr(10));
  END IF;

  IF p_show_menu_oravclog = 0 THEN
    dbms_lob.append(l_result, '<li>'                                || chr(10));
    IF l_tab = 5 THEN
      dbms_lob.append(l_result, '<A class="active" HREF="javascript:oraVCsubmitformGeneral(5);"' || '">');
    ELSE
      dbms_lob.append(l_result, '<A HREF="javascript:oraVCsubmitformGeneral(5);"' || '">');
    END IF;
    dbms_lob.append(l_result, 'Log');
    dbms_lob.append(l_result, '</A>'                                || chr(10));
    dbms_lob.append(l_result, '</li>'                               || chr(10));
  END IF;

  IF p_show_menu_objectversion = 0 THEN
    dbms_lob.append(l_result, '<li>'                                || chr(10));
    IF l_tab = 1 THEN
      dbms_lob.append(l_result, '<A class="active" HREF="javascript:oraVCsubmitformGeneral(1);"' || '">');
    ELSE
      dbms_lob.append(l_result, '<A HREF="javascript:oraVCsubmitformGeneral(1);"' || '">');
    END IF;

    dbms_lob.append(l_result, 'Versions');
    dbms_lob.append(l_result, '</A>'                                || chr(10));
    dbms_lob.append(l_result, '</li>'                               || chr(10));
  END IF;

  IF p_show_menu_versioncompare = 0 THEN
    dbms_lob.append(l_result, '<li>'                                || chr(10));
    IF l_tab = 2 THEN
      dbms_lob.append(l_result, '<A class="active" HREF="javascript:oraVCsubmitformGeneral(2);"' || '">');
    ELSE
      dbms_lob.append(l_result, '<A HREF="javascript:oraVCsubmitformGeneral(2);"' || '">');
    END IF;

    dbms_lob.append(l_result, 'Compare');
    dbms_lob.append(l_result, '</A>'                                || chr(10));
    dbms_lob.append(l_result, '</li>'                               || chr(10));
  END IF;

  IF p_show_menu_versiongenerate = 0 THEN
    dbms_lob.append(l_result, '<li>'                                || chr(10));
    IF l_tab = 4 THEN
      dbms_lob.append(l_result, '<A class="active" HREF="javascript:oraVCsubmitformGeneral(4);"' || '">');
    ELSE
      dbms_lob.append(l_result, '<A HREF="javascript:oraVCsubmitformGeneral(4);"' || '">');
    END IF;

    dbms_lob.append(l_result, 'Generator');
    dbms_lob.append(l_result, '</A>'                                || chr(10));
    dbms_lob.append(l_result, '</li>'                               || chr(10));
  END IF;

  IF p_show_menu_oravcapi = 0 THEN
    dbms_lob.append(l_result, '<li>'                                || chr(10));
    IF l_tab = 6 THEN
      dbms_lob.append(l_result, '<A class="active" HREF="javascript:oraVCsubmitformGeneral(6);"' || '">');
    ELSE
      dbms_lob.append(l_result, '<A HREF="javascript:oraVCsubmitformGeneral(6);"' || '">');
    END IF;

    dbms_lob.append(l_result, 'API');
    dbms_lob.append(l_result, '</A>'                                || chr(10));
    dbms_lob.append(l_result, '</li>'                               || chr(10));
  END IF;

  dbms_lob.append(l_result, '</ul>'                               || chr(10));

  IF 0 IN (p_show_title
          ,p_show_menu_admininfo
          ,p_show_menu_filter
          ,p_show_menu_oravclog
          ,p_show_menu_objectversion
          ,p_show_menu_versioncompare
          ,p_show_menu_versiongenerate
          ,p_show_menu_oravcapi
         ) THEN
    dbms_lob.append(l_result, '</div>'                               || chr(10));
    dbms_lob.append(l_result, '</div>'                               || chr(10));
  END IF;

  dbms_lob.append(l_result, '<div id="oravc_main_menu_div2">'     || chr(10));
  dbms_lob.append(l_result, '<table id="oravc_main_menu_table2">' || chr(10));

  dbms_lob.append(l_result, '<tr>'                                    || chr(10));
  dbms_lob.append(l_result, '<td>'                                    || chr(10));

  CASE
    WHEN l_tab = 0 THEN
      l_clob := showAdminInfo();

    WHEN l_tab = 1 THEN
      l_clob := showObjectsVersionForm(
                  p_object_version        => p_object_version_child
                 ,p_forceCompare          => l_forceCompare
                 ,p_report_type           => l_report_type
                 ,p_filters               => l_filters
                );

    WHEN l_tab = 2 THEN
      l_clob := showVersionCompare(
                  p_object_version        => p_object_version
                 ,p_object_version_child  => p_object_version_child
                 ,p_forceCompare          => l_forceCompare
                 ,p_report_type           => l_report_type
                 ,p_filters               => l_filters
                );

    WHEN l_tab = 4 THEN
      l_clob := showVersionGenerator(
                  p_object_version        => p_object_version
                 ,p_object_version_child  => p_object_version_child
                 ,p_forceCompare          => l_forceCompare
                 ,p_filters               => l_filters
                );

    WHEN l_tab = 5 THEN
      l_clob := showLog(
                  p_logs_to_display       => l_logs_to_display
                );

    WHEN l_tab = 6 THEN
      l_clob := showORAVC_API();

    WHEN l_tab = 7 THEN
      l_clob := showVersionsFilter('tab7', l_tab_prev);

    ELSE
      NULL;
  END CASE;

  dbms_lob.append(l_result, l_clob                      || chr(10));
  dbms_lob.append(l_result, '</td>'                     || chr(10));
  dbms_lob.append(l_result, '</tr>'                     || chr(10));

  dbms_lob.append(l_result, '</table>'                  || chr(10));
  dbms_lob.append(l_result, '</div>'                    || chr(10));

  dbms_lob.append(l_result, htf.bodyClose);

/*
  dbms_lob.append(l_result, '<footer>');
  -- here I'll place submit form.
  dbms_lob.append(l_result, '<FORM id="oraVCsubmitForm" name="oraVCsubmitForm" ACTION="' || l_base_url || '" METHOD="POST">');
  dbms_lob.append(l_result, '<input type="hidden" id="p_tab"                  name="p_tab" />');
  dbms_lob.append(l_result, '<input type="hidden" id="p_tab_prev"             name="p_tab_prev" />');
  dbms_lob.append(l_result, '<input type="hidden" id="p_object_version"       name="p_object_version" />');
  dbms_lob.append(l_result, '<input type="hidden" id="p_object_version_child" name="p_object_version_child" />');
  dbms_lob.append(l_result, '<input type="hidden" id="p_filters"              name="p_filters"/>');
  dbms_lob.append(l_result, '<input type="hidden" id="p_forceCompare"         name="p_forceCompare" />');
  dbms_lob.append(l_result, '<input type="hidden" id="p_report_type"          name="p_report_type" />');
  dbms_lob.append(l_result, '<input type="hidden" id="p_logs_to_display"      name="p_logs_to_display" />');
  dbms_lob.append(l_result, '<input type="hidden" id="p_custom_css"           name="p_custom_css"/>');
  dbms_lob.append(l_result, '</FORM>');
  dbms_lob.append(l_result, '</footer>');
*/
  -- here I want to call input values setup java script after page load
  -- function is in main javascript
  dbms_lob.append(l_result, '
    <script>
      //call after page loaded

      window.onload=afterPageLoad(''tab' || l_tab || ''') ;
    </script>
  '
  || chr(10));

  --dbms_lob.append(l_result, htf.htmlClose);

  RETURN l_result;

EXCEPTION
  WHEN OTHERS THEN
    ORAVC_ENGINE.add2log(
       p_message_type    => ORAVC_ENGINE.get_C_ERROR
      ,p_message_text    => 'ERROR IN ' || C_PACKAGE_NAME || '.' || l_function_name || chr(10)
      || SQLCODE || chr(10) || l_function_name || chr(10)
      || '     p_base_url => '             || p_base_url              || chr(10)
      || '     p_tab => '                  || p_tab                   || chr(10)
      || '     p_tab_prev => '             || p_tab_prev                   || chr(10)
      || '    ,p_object_version => '       || p_object_version        || chr(10)
      || '    ,p_object_version_child => ' || p_object_version_child  || chr(10)
      || '    ,p_filters => '              || p_filters          || chr(10)
      || '    ,p_forceCompare => '         || p_forceCompare          || chr(10)
      || '    ,p_report_type => '          || p_report_type           || chr(10)
      || '    ,p_logs_to_display => '      || p_logs_to_display       || chr(10)
      || '    ,p_custom_css => '           || p_custom_css            || chr(10)
      || SQLERRM
      ,p_message_place    => C_PACKAGE_NAME || '.' || l_function_name
      );
    RETURN SQLERRM || chr(10) || ' check Version Controll log ';

END oravc_webInfo;


PROCEDURE viewer_logout IS
BEGIN
   -- Open the HTTP header
   owa_util.mime_header('text/html', FALSE, NULL);

   -- Send a cookie to logout
   owa_cookie.send('WDB_GATEWAY_LOGOUT', 'YES', path=>'/');

   -- Close the HTTP header
   owa_util.http_header_close;

   -- Generate the page
   htp.p('You have been logged off from the OraVC Viewer');
END;

/*
<comments>
  in package specification

</comments>
*/
PROCEDURE viewer(
           p_base_url                   VARCHAR2  := G_BASE_URI
          ,p_tab                        NUMBER    := NULL
          ,p_tab_prev                   NUMBER    := NULL
          ,p_object_version             VARCHAR2  := NULL
          ,p_object_version_child       VARCHAR2  := NULL
          ,p_filters                    CLOB      := NULL
          ,p_forceCompare               NUMBER    := NULL
          ,p_report_type                NUMBER    := NULL
          ,p_logs_to_display            NUMBER    := NULL
          ,p_custom_css                 CLOB      := G_CSS_FIXED
          ,p_show_title                 NUMBER    := 0
          ,p_show_menu_admininfo        NUMBER    := 0
          ,p_show_menu_filter           NUMBER    := 0
          ,p_show_menu_oravclog         NUMBER    := 0
          ,p_show_menu_objectversion    NUMBER    := 0
          ,p_show_menu_versioncompare   NUMBER    := 0
          ,p_show_menu_versiongenerate  NUMBER    := 0
          ,p_show_menu_oravcapi         NUMBER    := 0
          ) IS
          
  l_buffer                              VARCHAR2(32000);
  l_resultCLOB                          CLOB;
BEGIN
  htp.htmlOpen;
  htp.bodyOpen;
  l_resultCLOB := oravc_engine_web.oravc_webInfo(
           p_base_url                   => p_base_url
          ,p_tab                        => p_tab
          ,p_tab_prev                   => p_tab_prev
          ,p_object_version             => p_object_version
          ,p_object_version_child       => p_object_version_child
          ,p_filters                    => p_filters
          ,p_forceCompare               => p_forceCompare
          ,p_report_type                => p_report_type
          ,p_logs_to_display            => p_logs_to_display
          ,p_custom_css                 => p_custom_css
          ,p_show_title                 => p_show_title
          ,p_show_menu_admininfo        => p_show_menu_admininfo
          ,p_show_menu_filter           => p_show_menu_filter
          ,p_show_menu_oravclog         => p_show_menu_oravclog
          ,p_show_menu_objectversion    => p_show_menu_objectversion
          ,p_show_menu_versioncompare   => p_show_menu_versioncompare
          ,p_show_menu_versiongenerate  => p_show_menu_versiongenerate
          ,p_show_menu_oravcapi         => p_show_menu_oravcapi
          );

  WHILE LENGTH(l_resultCLOB) > 0 LOOP
    BEGIN
      IF LENGTH(l_resultCLOB) > 16000 THEN
         l_buffer:= substr(l_resultCLOB,1,16000);
         htp.prn(l_buffer);
         l_resultCLOB:= substr(l_resultCLOB,LENGTH(l_buffer)+1);
      ELSE
         l_buffer := l_resultCLOB;
         htp.prn(l_buffer);
         l_resultCLOB:='';
         l_buffer := '';
      END IF;
    END;
  END LOOP;
  htp.bodyClose;
  htp.htmlClose;

END viewer;     

END ORAVC_ENGINE_WEB;
/
